package ca.uwo.android.directoryservice;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DirectorySearchListViewAdapter extends BaseAdapter {
	List<DirectorySearchData> list;
	LayoutInflater inflater;

	public DirectorySearchListViewAdapter(Context context) {
		inflater = LayoutInflater.from(context);
		list = null;
	}

	public void setData(List<DirectorySearchData> data) {
		list = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		DirectorySearchData item = list.get(position);			
		
		if(convertView == null) {
			row = inflater.inflate(android.R.layout.simple_list_item_1, null);
		}

		if(item != null) {
			TextView label = (TextView)row.findViewById(android.R.id.text1);
			label.setText(item.getFullName());
		}

		return row;
	}

	@Override
	public int getCount() {
		if(list == null) return 0;
		
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
